package com.cwx.mychat.login.authentication.phone;

import com.cwx.mychat.entity.po.UserInfo;
import org.springframework.security.authentication.AbstractAuthenticationToken;

/**
 * 作者： cwx
 * 时间： 2024/11/26 19:42
 * 版本： 1.0
 * 注释：
 */
public class PhoneAuthentication extends AbstractAuthenticationToken {

    private String phoneOrEmail;

    private String password;

    private UserInfo currentUser; //认证成功后，后台从数据库获取信息


    public PhoneAuthentication() {
        super(null);
    }

    @Override
    public Object getCredentials() {
        return isAuthenticated() ? null: password;
    }

    @Override
    public Object getPrincipal() {
        return isAuthenticated() ? currentUser : phoneOrEmail;
    }

    public String getPhoneOrEmail() {
        return phoneOrEmail;
    }

    public void setPhoneOrEmail(String phoneOrEmail) {
        this.phoneOrEmail = phoneOrEmail;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public UserInfo getCurrentUser() {
        return currentUser;
    }

    public void setCurrentUser(UserInfo currentUser) {
        this.currentUser = currentUser;
    }
}
